package com.ruoyi.project.system.average_income_comparison.controller;

import java.util.List;
import java.util.stream.Collectors;

import com.ruoyi.framework.web.page.PageDomain;
import com.ruoyi.framework.web.page.TableSupport;
import com.ruoyi.project.system.average_income_comparison.domain.AverageIncomeInfo;
import com.ruoyi.project.system.average_income_comparison.service.IAverageIncomeInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;


/**
 * 年度人均收入对比Controller
 *！！！！！注意！！！！！
 * 该模块的domain了busi_income_data表、base_family_info表、base_family_member_info表
 * @author fhk
 * @date 2023-03-07
 */
@Controller
@RequestMapping("system/average_income_info")
public class AverageIncomeInfoController extends BaseController{
    private String prefix = "system/average_income_info";
    @Autowired
    private IAverageIncomeInfoService averageIncomeInfoService;

    @GetMapping()
    public String average(){
        return prefix + "/average";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo comparison(AverageIncomeInfo averageIncomeInfo){
        List<AverageIncomeInfo> list = averageIncomeInfoService.findBackIntoPoverty(averageIncomeInfo);
        //重构分页
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        int num = list.size();
        list = list.stream().skip((pageNum - 1) * pageSize).limit(pageSize).collect(Collectors.toList());
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setTotal(num);
        rspData.setRows(list);
        return rspData;
    }
}
